package com.sys.dao;

import com.sys.data.code;
import com.sys.data.sqlMap;
import com.sys.data.sqlStruct;
import com.sys.util.console;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.sql.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static com.sys.util.floatUtils.floorFloat;

@SuppressWarnings("unused")
class ConnectSQL {
  private static final String Driver = "com.microsoft.mysql.jdbc.SQLServerDriver";
  private static final String DataBaseName = "stonetech_gp_sys";//数据库名称
  private static final String Url = "jdbc:sqlserver://localhost:1433;DatabaseName=" + DataBaseName;//连接数据库语句
  //驱动程序名
  private static final String mySqlDriver = "com.mysql.jdbc.Driver";
  //URL指向要访问的数据库名mydata
  private static final String mySqlUrl = "jdbc:mysql://rm-uf63j5847y514cp2m4o.mysql.rds.aliyuncs.com:3306/" + DataBaseName;//连接mysql数据库语句
  private static final String DataBaseUserName = "sonetech";//连接数据库账号
  private static final String DataBasePassWord = "sonetech_0116";//连接数据库密码

  /**
   * 正则表达式：验证手机号
   */
  static final String IphoneRule = "^((17[0-9])|(14[0-9])|(13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";

  /**
   * 连接数据库
   *
   * @return Connection
   */
  private Connection ConnectToDataBase() {
    try {
      Class.forName(mySqlDriver);
      return DriverManager.getConnection(mySqlUrl, DataBaseUserName, DataBasePassWord);
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }
  }

  /**
   * 关闭数据库连接
   *
   * @param conn 连接
   */
  private void closeConnect(Connection conn) {
    try {
      if (conn == null) return;
      conn.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  /**
   * 结果集关闭
   *
   * @param rs ResultSet
   */
  private void closeResultRS(ResultSet rs) {
    try {
      if (rs == null) return;
      rs.close();
    } catch (Exception e) {
      console.err(e);
    }
  }

  /**
   * 关闭连机器
   *
   * @param statement PreparedStatement
   */
  private void closePreparedStatement(PreparedStatement statement) {
    try {
      if (statement == null) return;
      statement.close();
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }

  /**
   * 检查T1是否超过T2
   *
   * @param T1 T1时间
   * @param T2 T2时间
   * @return true/false
   * @throws Exception 异常
   */
  protected boolean CheckTime(String T1, String T2) throws Exception {
    SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
    Long beginL = format.parse(T1).getTime();
    Long endL = format.parse(T2).getTime();
    Long hour = ((endL - beginL) % 86400000) / 3600000;
    Long min = ((endL - beginL) % 86400000 % 3600000) / 60000;

    if (hour <= 0 && min < 0) {
      console.log("时间到..");
      return false;
    }
    return true;
  }

  /**
   * timestamp转String
   *
   * @param Ts 需要转的timestamp值
   * @return string
   */
  private String TimeStampToString(Timestamp Ts) {
    if (Ts == null) return "";
    DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String tsStr;
    tsStr = sdf.format(Ts);
    return tsStr;
  }

  /**
   * String转timestamp
   *
   * @param Str 需要转的string值
   * @return timestamp
   */
  private Timestamp StringToTimeStamp(String Str) {
    Timestamp ts = new Timestamp(System.currentTimeMillis());
    try {
      ts = Timestamp.valueOf(Str);
    } catch (Exception e) {
      e.printStackTrace();
    }
    return ts;
  }

  /**
   * 两个日期相差天数（EndDate > StartDate）
   *
   * @param StartDays 开始时间
   * @param EndDays   结束时间
   * @return 相差天数
   */
  protected int differentDays(String StartDays, String EndDays) {
    try {
      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//小写的mm表示的是分钟
      java.util.Date StartDate = sdf.parse(StartDays);
      Date EndDate = sdf.parse(EndDays);

      Calendar cal1 = Calendar.getInstance();
      cal1.setTime(StartDate);

      Calendar cal2 = Calendar.getInstance();
      cal2.setTime(EndDate);
      int day1 = cal1.get(Calendar.DAY_OF_YEAR);
      int day2 = cal2.get(Calendar.DAY_OF_YEAR);

      int year1 = cal1.get(Calendar.YEAR);
      int year2 = cal2.get(Calendar.YEAR);
      if (year1 != year2)   //同一年
      {
        int timeDistance = 0;
        for (int i = year1; i < year2; i++) {
          if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0)    //闰年
          {
            timeDistance += 366;
          } else    //不是闰年
          {
            timeDistance += 365;
          }
        }

        return timeDistance + (day2 - day1);
      } else    //不同年
      {
        System.out.println("判断day2 - day1 : " + (day2 - day1));
        return day2 - day1;
      }
    } catch (Exception e) {
      e.printStackTrace();
      return 0;
    }
  }

  /**
   * 执行增、删、改SQL语句
   *
   * @param sql   SQL语句
   * @param param 值map
   * @return 状态码
   */
  int executeUpdate(String sql, sqlMap param) {
    if (!sql.toUpperCase().contains("UPDATE".toUpperCase()) && !sql.toUpperCase().contains("DELETE".toUpperCase()) && !sql.toUpperCase().contains("INSERT".toUpperCase())) {
      console.log("不是增 删 改语句!");
      return -1;
    }

    int returnCode = 0;
    Connection conn = ConnectToDataBase();
    PreparedStatement statement = null;
    try {
      assert conn != null;
      statement = conn.prepareStatement(sql);
      int n = 0;
      for (Map.Entry<Integer, sqlStruct> entry : param.entrySet()) {
        //根据setObject类型set值
        switch (entry.getValue().getType()) {
          case 93:
            Timestamp toTimeStamp = StringToTimeStamp(entry.getValue().getValue().toString());
            statement.setObject(entry.getKey(), toTimeStamp, entry.getValue().getType());
            break;
          default:
            statement.setObject(entry.getKey(), entry.getValue().getValue(), entry.getValue().getType());
            break;
        }
        n++;
      }
      returnCode = statement.executeUpdate();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      closeConnect(conn);
      closePreparedStatement(statement);
    }
    return returnCode;
  }


  /**
   * SQL 查询语句
   *
   * @param sql   SQL语句
   * @param param 哈希Map
   * @return 结果集
   */
  List<Map<String, Object>> executeQuery(String sql, sqlMap param) {
    if (!sql.toUpperCase().contains("SELECT".toUpperCase())) {
      console.log("不是查询语句!");
      return null;
    }

    ResultSet rs = null;
    List<Map<String, Object>> list = null;
    Connection conn = ConnectToDataBase();
    PreparedStatement statement = null;
    try {
      assert conn != null;
      statement = conn.prepareStatement(sql);
      int n = 0;
      for (Map.Entry<Integer, sqlStruct> entry : param.entrySet()) {
        statement.setObject(entry.getKey(), entry.getValue().getValue(), entry.getValue().getType());
        n++;
      }
      rs = statement.executeQuery();
      list = new ArrayList<>();
      ResultSetMetaData rsm = rs.getMetaData();
      Map<String, Object> map;
      while (rs.next()) {
        map = new HashMap<>();
        for (int i = 1; i <= rsm.getColumnCount(); i++) {
          //根据类型取值
          switch (rsm.getColumnType(i)) {
            case 93://timestamp转换
              String str = TimeStampToString(rs.getTimestamp(rsm.getColumnName(i)));
              map.put(rsm.getColumnName(i), str);
              break;
            case 6:
            case 7://只保留3位小数
              float f = floorFloat(rs.getFloat(rsm.getColumnName(i)), 2);
              map.put(rsm.getColumnName(i), f);
              break;
            default:
              map.put(rsm.getColumnName(i), rs.getObject(rsm.getColumnName(i)));
              break;
          }
        }
        list.add(map);
      }
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      closeConnect(conn);
      closePreparedStatement(statement);
      closeResultRS(rs);
    }
    return list;
  }

  boolean CheckLegal(String Str, String Rule) {
    //正则表达式模式
    Pattern p = Pattern.compile(Rule);
    //正则表达式的匹配器
    Matcher m = p.matcher(Str);
    //返回boolean
    return m.matches();
  }

  /**
   * list帮助类
   *
   * @param list list
   * @return JSON
   */
  JSONObject listHelperQuery(List<Map<String, Object>> list) {
    JSONObject resultJson = new JSONObject();
    if (list == null) {
      console.log("err listHelp Not code");
      resultJson.put("code", code.ErrorSelect.value());
      resultJson.put("msg", code.ErrorSelect.msg());
      return resultJson;
    }

    if (list.size() == 0) {
      resultJson.put("code", code.SQLSelectNull.value());
      resultJson.put("msg", code.SQLSelectNull.msg());
    } else {
      forMapList(list, resultJson);
    }
    return resultJson;
  }

  /**
   * list帮助类
   *
   * @param list list
   * @return JSON
   */
  JSONObject listHelperQuery(List<Map<String, Object>> list, code mCode) {
    JSONObject resultJson = new JSONObject();
    if (list == null) {
      console.log("err listHelp code!..");
      resultJson.put("code", code.ErrorSelect.value());
      resultJson.put("msg", code.ErrorSelect.msg());
      return resultJson;
    }

    if (list.size() == 0) {
      resultJson.put("code", mCode.value());
      resultJson.put("msg", mCode.msg());
    } else {
      forMapList(list, resultJson);
    }
    return resultJson;
  }

  private void forMapList(List<Map<String, Object>> list, JSONObject resultJson) {
    for (Map<String, Object> li : list) {
      for (Map.Entry<String, Object> entry : li.entrySet()) {
        resultJson.put(entry.getKey(), entry.getValue());
      }
    }
    resultJson.put("code", code.OK.value());
    resultJson.put("msg", code.OK.msg());
  }

  /**
   * list帮助类（2个值以上）
   *
   * @param list    list
   * @param keyName JSON键值
   * @return JSON
   */
  JSONObject listHelperQuery(List<Map<String, Object>> list, String keyName, code mCode) {
    JSONObject resultJson = new JSONObject();
    if (list == null) {
      console.err("err listHelp code list!..");
      resultJson.put("code", code.ErrorSelect.value());
      resultJson.put("msg", code.ErrorSelect.msg());
      return resultJson;
    }
    JSONArray resultArr = new JSONArray();
    if (list.size() == 0) {
      resultJson.put("code", mCode.value());
      resultJson.put("msg", mCode.msg());
    } else {
      for (Map<String, Object> li : list) {
        JSONObject goodsJson = new JSONObject();
        for (Map.Entry<String, Object> entry : li.entrySet()) {
          goodsJson.put(entry.getKey(), entry.getValue());
        }
        resultArr.add(goodsJson);
      }
      resultJson.put("code", code.OK.value());
      resultJson.put("msg", code.OK.msg());
      resultJson.put(keyName, resultArr);
    }
    return resultJson;
  }

  /**
   * 判断dt1是否在dt2日期前面
   *
   * @param DATE1 dt1
   * @param DATE2 dt2
   * @return true/false
   */
  public boolean compare_date(String DATE1, String DATE2) {
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm");
    try {
      Date dt1 = df.parse(DATE1);
      Date dt2 = df.parse(DATE2);
      if (dt1.getTime() > dt2.getTime()) {
        System.out.println("dt1 在dt2前");
        return true;
      } else if (dt1.getTime() < dt2.getTime()) {
        System.out.println("dt1在dt2后");
        return false;
      } else {
        return false;
      }
    } catch (Exception exception) {
      exception.printStackTrace();
    }
    return false;
  }

  /**
   * 获取这条记录的所有信息
   *
   * @param SQLName        获取的数据库名
   * @param Condition      获取的条件名
   * @param ConditionValue 获取的条件值
   * @param ConditionType  获取的条件类型
   * @return JSON
   */
  JSONObject getSqlInfo(String SQLName, String Condition, Object ConditionValue, int ConditionType) {
    JSONObject resultJson;
    String sql = "SELECT * FROM " + SQLName + " WHERE " + Condition + " = ?";
    sqlMap sqlM = new sqlMap();
    sqlM.put(1, ConditionValue, ConditionType);
    List<Map<String, Object>> list = executeQuery(sql, sqlM);
    resultJson = listHelperQuery(list);
    return resultJson;
  }

  /**
   * 从数据库获取信息(一条数据)
   *
   * @param Attr1          获取第一个值
   * @param SQLName        获取的数据库名
   * @param Condition      获取的条件名
   * @param ConditionValue 获取的条件值
   * @param ConditionType  获取的条件类型
   * @return JSON
   */
  JSONObject getSqlInfo(String Attr1, String SQLName, String Condition, Object ConditionValue, int ConditionType) {
    JSONObject resultJson;
    String sql = "SELECT " + Attr1 + " FROM " + SQLName + " WHERE " + Condition + " = ?";
    sqlMap sqlM = new sqlMap();
    sqlM.put(1, ConditionValue, ConditionType);
    List<Map<String, Object>> list = executeQuery(sql, sqlM);
    resultJson = listHelperQuery(list);
    return resultJson;
  }

  /**
   * 从数据库获取信息2(一条数据)
   *
   * @param Attr1          获取第一个值
   * @param Attr2          获取第二个值
   * @param SQLName        获取的数据库名
   * @param Condition      获取的条件名
   * @param ConditionValue 获取的条件值
   * @param ConditionType  获取的条件类型
   * @return JSON
   */
  JSONObject getSqlInfo(String Attr1, String Attr2, String SQLName, String Condition, Object ConditionValue, int ConditionType) {
    JSONObject resultJson;
    String sql = "SELECT " + Attr1 + "," + Attr2 + " FROM " + SQLName + " WHERE " + Condition + " = ?";
    sqlMap sqlM = new sqlMap();
    sqlM.put(1, ConditionValue, ConditionType);
    List<Map<String, Object>> list = executeQuery(sql, sqlM);
    resultJson = listHelperQuery(list);
    return resultJson;
  }

  /**
   * 从数据库获取信息3(一条数据)
   *
   * @param Attr1          获取第一个值
   * @param Attr2          获取第二个值
   * @param Attr3          获取第三个值
   * @param SQLName        获取的数据库名
   * @param Condition      获取的条件名
   * @param ConditionValue 获取的条件值
   * @param ConditionType  获取的条件类型
   * @return JSON
   */
  JSONObject getSqlInfo(String Attr1, String Attr2, String Attr3, String SQLName, String Condition, Object ConditionValue, int ConditionType) {
    JSONObject resultJson;
    String sql = "SELECT " + Attr1 + "," + Attr2 + "," + Attr3 + " FROM " + SQLName + " WHERE " + Condition + " = ?";
    sqlMap sqlM = new sqlMap();
    sqlM.put(1, ConditionValue, ConditionType);
    List<Map<String, Object>> list = executeQuery(sql, sqlM);
    resultJson = listHelperQuery(list);
    return resultJson;
  }


  /**
   * 数据库更新
   *
   * @param Attr1          第一个参数
   * @param Attr1Value     第一个参数的值
   * @param Attr1Type      第一个参数的类型
   * @param SQLName        数据库名
   * @param Condition      条件
   * @param ConditionValue 条件值
   * @param ConditionType  条件类型
   * @return 1/0
   */
  int setSqlInfo(String Attr1, Object Attr1Value, int Attr1Type, String SQLName, String Condition, Object ConditionValue, int ConditionType, boolean isADD) {
    if (Attr1Type == 4 && isADD) {
      JSONObject obcJson = getSqlInfo(Attr1, SQLName, Condition, ConditionValue, ConditionType);
      int oldAttr = obcJson.getInt(Attr1);
      int newAttr = Integer.parseInt(Attr1Value.toString());
      newAttr += oldAttr;
      Attr1Value = newAttr;
    }

    if (Attr1Type == 6 && isADD) {
      JSONObject obcJson = getSqlInfo(Attr1, SQLName, Condition, ConditionValue, ConditionType);
      float oldAttr = Float.valueOf(obcJson.getString(Attr1));
      float newAttr = Float.valueOf(Attr1Value.toString());
      newAttr += oldAttr;
      Attr1Value = newAttr;
    }
    String sql = "UPDATE " + SQLName + " SET " + Attr1 + " = ? WHERE " + Condition + " = ?";

    sqlMap sqlM = new sqlMap();
    sqlM.put(1, Attr1Value, Attr1Type);
    sqlM.put(2, ConditionValue, ConditionType);
    return executeUpdate(sql, sqlM);
  }

  /**
   * 数据库更新
   *
   * @param Attr1          第一个参数
   * @param Attr1Value     第一个参数的值
   * @param Attr1Type      第一个参数的类型
   * @param Attr2          第二个参数
   * @param Attr2Value     第二个参数的值
   * @param Attr2Type      第二个参数的类型
   * @param SQLName        数据库
   * @param Condition      条件
   * @param ConditionValue 条件值
   * @param ConditionType  条件类型
   * @return 1/0
   */
  protected int setSqlInfo(String Attr1, Object Attr1Value, int Attr1Type, String Attr2, Object Attr2Value, int Attr2Type, String SQLName, String Condition, Object ConditionValue, int ConditionType, boolean isADD1, boolean isADD2) {
    if (Attr1Type == 4 && isADD1) {
      JSONObject obcJson = getSqlInfo(Attr1, SQLName, Condition, ConditionValue, ConditionType);
      int oldAttr = obcJson.getInt(Attr1);
      int newAttr = Integer.parseInt(Attr1Value.toString());
      newAttr += oldAttr;
      Attr1Value = newAttr;
    }

    if (Attr1Type == 6 && isADD1) {
      JSONObject obcJson = getSqlInfo(Attr1, SQLName, Condition, ConditionValue, ConditionType);
      float oldAttr = Float.valueOf(obcJson.getString(Attr1));
      float newAttr = Float.valueOf(Attr1Value.toString());
      newAttr += oldAttr;
      Attr1Value = newAttr;
    }

    if (Attr2Type == 4 && isADD2) {
      JSONObject obcJson = getSqlInfo(Attr2, SQLName, Condition, ConditionValue, ConditionType);
      int oldAttr = obcJson.getInt(Attr2);
      int newAttr = Integer.parseInt(Attr2Value.toString());
      newAttr += oldAttr;
      Attr2Value = newAttr;
    }

    if (Attr2Type == 6 && isADD2) {
      JSONObject obcJson = getSqlInfo(Attr2, SQLName, Condition, ConditionValue, ConditionType);
      float oldAttr = Float.valueOf(obcJson.getString(Attr2));
      float newAttr = Float.valueOf(Attr2Value.toString());
      newAttr += oldAttr;
      Attr2Value = newAttr;
    }
    String sql = "UPDATE " + SQLName + " SET " + Attr1 + " = ?," + Attr2 + " = ? WHERE " + Condition + " = ?";
    sqlMap sqlM = new sqlMap();
    sqlM.put(1, Attr1Value, Attr1Type);
    sqlM.put(2, Attr2Value, Attr2Type);
    sqlM.put(3, ConditionValue, ConditionType);
    return executeUpdate(sql, sqlM);
  }

  /**
   * 数据库更新
   *
   * @param Attr1          第一个参数
   * @param Attr1Value     第一个参数的值
   * @param Attr1Type      第一个参数的类型
   * @param Attr2          第二个参数
   * @param Attr2Value     第二个参数的值
   * @param Attr2Type      第二个参数的类型
   * @param Attr3          第三个参数
   * @param Attr3Value     第三个参数的值
   * @param Attr3Type      第三个参数的类型
   * @param SQLName        数据库
   * @param Condition      条件
   * @param ConditionValue 条件值
   * @param ConditionType  条件类型
   * @return 1/0
   */
  protected int setSqlInfo(String Attr1, Object Attr1Value, int Attr1Type, String Attr2, Object Attr2Value, int Attr2Type, String Attr3, Object Attr3Value, int Attr3Type, String SQLName, String Condition, Object ConditionValue, int ConditionType, boolean isADD1, boolean isADD2, boolean isADD3) {
    if (Attr1Type == 4 && isADD1) {
      JSONObject obcJson = getSqlInfo(Attr1, SQLName, Condition, ConditionValue, ConditionType);
      int oldAttr = obcJson.getInt(Attr1);
      int newAttr = Integer.parseInt(Attr1Value.toString());
      newAttr += oldAttr;
      Attr1Value = newAttr;
    }

    if (Attr1Type == 6 && isADD1) {
      JSONObject obcJson = getSqlInfo(Attr1, SQLName, Condition, ConditionValue, ConditionType);
      float oldAttr = Float.valueOf(obcJson.getString(Attr1));
      float newAttr = Float.valueOf(Attr1Value.toString());
      newAttr += oldAttr;
      Attr1Value = newAttr;
    }

    if (Attr2Type == 4 && isADD2) {
      JSONObject obcJson = getSqlInfo(Attr2, SQLName, Condition, ConditionValue, ConditionType);
      int oldAttr = obcJson.getInt(Attr2);
      int newAttr = Integer.parseInt(Attr2Value.toString());
      newAttr += oldAttr;
      Attr2Value = newAttr;
    }

    if (Attr2Type == 6 && isADD2) {
      JSONObject obcJson = getSqlInfo(Attr2, SQLName, Condition, ConditionValue, ConditionType);
      float oldAttr = Float.valueOf(obcJson.getString(Attr2));
      float newAttr = Float.valueOf(Attr2Value.toString());
      newAttr += oldAttr;
      Attr2Value = newAttr;
    }

    if (Attr3Type == 4 && isADD3) {
      JSONObject obcJson = getSqlInfo(Attr3, SQLName, Condition, ConditionValue, ConditionType);
      int oldAttr = obcJson.getInt(Attr3);
      int newAttr = Integer.parseInt(Attr3Value.toString());
      newAttr += oldAttr;
      Attr3Value = newAttr;
    }

    if (Attr3Type == 6 && isADD3) {
      JSONObject obcJson = getSqlInfo(Attr3, SQLName, Condition, ConditionValue, ConditionType);
      float oldAttr = Float.valueOf(obcJson.getString(Attr3));
      float newAttr = Float.valueOf(Attr3Value.toString());
      newAttr += oldAttr;
      Attr3Value = newAttr;
    }

    String sql = "UPDATE " + SQLName + " SET " + Attr1 + " = ?," + Attr2 + " = ?," + Attr3 + " = ? WHERE " + Condition + " = ?";
    sqlMap sqlM = new sqlMap();
    sqlM.put(1, Attr1Value, Attr1Type);
    sqlM.put(2, Attr2Value, Attr2Type);
    sqlM.put(3, Attr3Value, Attr3Type);
    sqlM.put(4, ConditionValue, ConditionType);
    return executeUpdate(sql, sqlM);
  }

  private JSONObject SelectSql(String SQLName, String[] Attr, String[] Condition, sqlMap sqlM, code mCode, String listName) {
    JSONObject resultJson = new JSONObject();
    if (Attr.length == 0) {
      resultJson.put("code", code.ErrorSelect.value());
      resultJson.put("msg", code.ErrorSelect.msg());
      return resultJson;
    }
    StringBuilder sql = new StringBuilder("SELECT ");
    for (int i = 0; i < Attr.length; i++) {
      sql.append(Attr[i]);
      if (i != Attr.length - 1) {
        sql.append(",");
      }
    }
    sql.append(" FROM ").append(SQLName);
    if (Condition.length != 0) {
      sql.append(" WHERE ");
      for (int i = 0; i < Condition.length; i++) {
        sql.append(Condition[i]);
        sql.append(" = ?");
        if (i != Condition.length - 1) {
          sql.append(" AND ");
        }
      }
    }
    console.log(sql);
    List<Map<String, Object>> list = executeQuery(sql.toString(), sqlM);
    if (mCode != null && listName != null) {
      return listHelperQuery(list, listName, mCode);
    }
    if (mCode != null) {
      return listHelperQuery(list, mCode);
    }
    return listHelperQuery(list);
  }

  protected JSONObject SelectSqlInfo(String SQLName, String[] Attr, String[] Condition, sqlMap sqlM) {
    return SelectSql(SQLName, Attr, Condition, sqlM, null, null);
  }

  protected JSONObject SelectSqlInfo(String SQLName, String[] Attr, String[] Condition, sqlMap sqlM, code mCode) {
    return SelectSql(SQLName, Attr, Condition, sqlM, mCode, null);
  }

  protected JSONObject SelectSqlInfo(String SQLName, String[] Attr, String[] Condition, sqlMap sqlM, code mCode, String listName) {
    return SelectSql(SQLName, Attr, Condition, sqlM, mCode, listName);
  }
}
